{% extends 'layout.html' %}
{% load static %}

{% block content %}
    <div class="container-fluid" style="margin-top: 20px;">

        <div class="col-md-12">
            <div class="panel panel-info mystyle-panel">
                <div class="panel-heading">
                    添加用户
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" method="post" action="" novalidate onsubmit="checkAddUser(this);">
                        {% for field in user_form %}
                            {% csrf_token %}
                            <div class="form-group {% if field.errors %}has-error{% else %}has-success{% endif %}">
                                <label for="{{ field.id_for_label }}"
                                       class="col-sm-2 control-label">{{ field.label }}</label>
                                <div class="col-sm-6">
                                    {{ field }}
                                    <span class="help-block">{{ field.errors.0 }}</span>
                                </div>
                            </div>
                        {% endfor %}
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-6">
                                <button type="submit" class="btn btn-default">添加</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block js %}
    <script src="{% static 'plugins/jquery/jquery.md5.js' %}"></script>
    <script>
    function checkAddUser(_this){
        var pwd = $(_this).find('input[name=password]').val();
        if($.trim(pwd)){
            pwd_md5 = $.md5(pwd);
            $(_this).find('input[name=password]').val(pwd_md5);
        }
        return true;
    }
    </script>
{% endblock %}